<!-- 账号密码登录页 -->
<template>
	<view class="uni-content pt10 pb20">
		<!-- 顶部文字 -->
		<text class="uni-content-title-line mb20">绑定已有账号</text>
		<uni-forms>
			<uni-forms-item name="username">
				<uni-easyinput :focus="focusUsername" @blur="focusUsername = false" class="input-box" v-model="username"
					placeholder="请输入用户名" />
			</uni-forms-item>
			<uni-forms-item name="password">
				<uni-easyinput :focus="focusPassword" @blur="focusPassword = false" class="input-box" clearable
					type="password" v-model="password" placeholder="请输入密码" />
			</uni-forms-item>
			<button class="blue-btn" type="default" @click="bindSubmit">绑 定</button>
		</uni-forms>
		<!-- 忘记密码 -->
		<view class="link-box">
			<text class="link-box-left" @click="navigateToFun('/pages/ucenter/forgetPwd/index')">忘记密码？</text>
			<text class="link-box-right" @click="navigateToFun('/pages/ucenter/register/register')">注册账号</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				"password": "",
				"username": "",
				"focusUsername": false,
				"focusPassword": false
			}
		},
		onShow() {},
		methods: {
			/**
			 * 密码登录
			 */
			bindSubmit() {
				if (!this.username.length) {
					this.focusUsername = true
					return uni.showToast({
						title: '请输入用户名',
						icon: 'none'
					});
				}
				if (!this.password.length) {
					this.focusPassword = true
					return uni.showToast({
						title: '请输入密码',
						icon: 'none'
					});
				}
				const openid = uni.getStorageSync('userOpenId');
				let data = {
					"password": this.password,
					"username": this.username,
					"openId": openid
				}
				this.$post(this.$api.wx.ucenter.mobileLogin, data).then(res => {
					uni.setStorage({
						key: "gkms-userInfo",
						data: res.userInfo
					})
					uni.setStorage({
						key: "token",
						data: res.token
					})
					uni.showToast({
						title: "绑定成功",
						icon: 'success'
					});
					setTimeout(() => {
						this.$loginSuccessGoFun()
					}, 1500)
				}).catch(e => {
					uni.showToast({
						title: e.data.msg,
						icon: 'none'
					});
				})
			},
			navigateToFun(url) {
				uni.navigateTo({
					url: url,
					fail(e) {
						console.error(e);
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "../common/style/uc-common.scss";
</style>
